(function($) {

  $.fn.serializeObject = function()
  {
     var o = {};
     var a = this.serializeArray();
     $.each(a, function() {
         if (o[this.name]) {
             if (!o[this.name].push) {
                 o[this.name] = [o[this.name]];
             }
             o[this.name].push(this.value || '');
         } else {
             o[this.name] = this.value || '';
         }
     });
     return o;
  };
  $.fn.clickToggle = function(func1, func2) {
      var funcs = [func1, func2];
      this.data('toggleclicked', 0);
      this.click(function() {
          var data = $(this).data();
          var tc = data.toggleclicked;
          $.proxy(funcs[tc], this)();
          data.toggleclicked = (tc + 1) % 2;
      });
      return this;
  };
}(jQuery));

function setCookie(cname, cvalue, exdays) {
    var d = new Date();
    var expires = "";
    if(exdays != "") {
      d.setTime(d.getTime() + (exdays*24*60*60*1000));
      expires = "; expires="+d.toUTCString();
  }
    document.cookie = cname + "=" + cvalue + expires;
}

function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
    }
    return "";
}

function checkCookie() {
    var user = getCookie("username");
    if (user != "") {
        alert("Welcome again " + user);
    } else {
        user = prompt("Please enter your name:", "");
        if (user != "" && user != null) {
            setCookie("username", user, 365);
        }
    }
}
function getLocation()
{
  if (navigator.geolocation)
  {
    navigator.geolocation.watchPosition(showPosition);
  }
  else{ alert("Shaphira khong the lay duoc vi tri cua ban");}
}
function showPosition(position)
{
  setCookie('Latitude',position.coords.latitude,'');
  setCookie('Longitude',position.coords.longitude,'');
}